<?php
/**
 * Created by 张彪.
 * User: 小马出行
 * Date: 2017/12/25
 * Time: 17:21
 */
namespace app\admin\logic;
use think\Db;
use think\Model;
class DriverServiceLogic extends Model
{
    /**
     * 获取乘客遗失物品列表
     * @param $map
     * @param $page
     * @param $limit
     * @param $field
     * @return false|\PDOStatement|string|\think\Collection
     * */
    public function getLostList($page=1,$limit=10,$map=array(),$field='a.*')
    {
        return Db::name('lost_driver_declare a')->join(['xm_driver_base'=>'b'],'b.driver_id = a.driver_id','LEFT')
            ->join(['xm_driver_info'=>'c'],'b.driver_id = c.driver_id','LEFT')
            ->page($page,$limit)->where($map)->field($field)->order('lost_id desc,is_dispose desc')->select();
    }

    /**
     * 获取乘客遗失物品详情
     * @param $lost_id
     * @param $field
     * @return false|\PDOStatement|string|\think\Collection
     *  */
    public function getLostDetailById($lost_id,$field='a.*')
    {
        return Db::name('lost_driver_declare a')->join(['xm_driver_base'=>'b'],'b.driver_id = a.driver_id','LEFT')
            ->join('admin c','c.admin_id = a.handler_id','LEFT')
            ->where('a.lost_id='.$lost_id)->field($field)->find();
    }

    /**
     * 更新乘客遗失物品信息
     * @param $map
     * @param $data
     * @return false|\PDOStatement|string|\think\Collection
     *  */
    public function renewLost($map,$data)
    {
        return Db::name('lost_driver_declare')->where($map)->update($data);
    }

    /**
     * 获取车辆故障列表
     * @param $map
     * @param $page
     * @param $limit
     * @param $field
     * @return false|\PDOStatement|string|\think\Collection
     * */
    public function getBreakdownList($page=1,$limit=10,$map=array(),$field='a.*')
    {
        return Db::name('car_breakdown a')->join(['xm_driver_base'=>'b'],'b.driver_id = a.driver_id','LEFT')
            ->join('car_info c','c.car_id = a.car_id','LEFT')
            ->join(['xm_driver_info'=>'d'],'b.driver_id = d.driver_id','LEFT')
            ->page($page,$limit)->where($map)->field($field)->order('break_id desc,is_repaired desc')->select();
    }

    /**
     * 获取车辆故障详情
     * @param $break_id
     * @param $field
     * @return false|\PDOStatement|string|\think\Collection
     *  */
    public function getBreakdownDetailById($break_id,$field='a.*')
    {
        return Db::name('car_breakdown a')->join(['xm_driver_base'=>'b'],'b.driver_id = a.driver_id','LEFT')
            ->join('car_info c','c.car_id = a.car_id','LEFT')
            ->where('a.break_id='.$break_id)->field($field)->find();
    }

    /**
     * 获取特殊情况报备列表
     * @param $map
     * @param $page
     * @param $limit
     * @param $field
     * @return false|\PDOStatement|string|\think\Collection
     * */
    public function getSpecialList($page=1,$limit=10,$map=array(),$field='a.*')
    {
        return Db::name('exceptional_case a')->join(['xm_driver_base'=>'b'],'b.driver_id = a.driver_id','LEFT')
            ->join(['xm_driver_info'=>'c'],'b.driver_id = c.driver_id','LEFT')
            ->page($page,$limit)->where($map)->field($field)->order('case_id desc')->select();
    }

    /**
     * 获取车辆故障详情
     * @param $case_id
     * @param $field
     * @return false|\PDOStatement|string|\think\Collection
     *  */
    public function getSpecialDetailById($case_id,$field='a.*')
    {
        return Db::name('exceptional_case a')->join(['xm_driver_base'=>'b'],'b.driver_id = a.driver_id','LEFT')
            ->where('a.case_id='.$case_id)->field($field)->find();
    }
}